package com.example.demo.config;


public class WGSUtil {

    /**
     * wgs转tile，zoom按照默认18层级
     *
     * @param j 经度
     * @param w 纬度
     * @return
     */
    public static int[] wgs_to_tile(double j, double w) {
        if (j < 0) {
            j = 180 + j;
        } else {
            j += 180;
        }
        j /= 360;
        w = Math.min(w, 85.0511287798);
        w = Math.max(w, -85.0511287798);
        w = Math.log(Math.tan((90 + w) * Math.PI / 360)) / (Math.PI / 180);
        w /= 180;
        w = 1 - (w + 1) / 2;
        int num = (int) Math.pow(2, 18);
        int x = (int) Math.floor(j * num);
        int y = (int) Math.floor(w * num);
        return new int[]{x, y};
    }
}